import 'package:flutter/material.dart';
import 'package:flutter_blog_manage_study/res/colors.dart';
import 'package:get/get.dart';

/// * 作者: Tao
/// * 日期: 2024/3/22
/// * 时间: 15:38
/// * 描述: 公共标题栏
class ToolBar extends StatefulWidget {
  ///标题文字
  final String title;

  ///右侧文字
  final String endText;

  ///是否显示右侧
  final bool isShowEnd;

  ///背景颜色
  final Color backgroundColor;

  ///背景颜色
  final Color backColor;

  final VoidCallback? backOnTap;

  const ToolBar(
      {super.key,
      this.title = "",
      this.endText = "",
      this.isShowEnd = false,
      this.backgroundColor = Colors.white,
      this.backColor = ColorStyle.color_B8C0D4,
      this.backOnTap});

  @override
  State<ToolBar> createState() => _ToolBarState();
}

class _ToolBarState extends State<ToolBar> {
  @override
  Widget build(BuildContext context) {
    return Material(
      color: widget.backgroundColor,
      child: SafeArea(
        top: true,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween, // 主轴对齐方式
          children: [
            InkWell(
              // 返回,点击事件，水波纹效果
              borderRadius: const BorderRadius.all(
                Radius.circular(20),
              ),
              onTap: widget.backOnTap ?? () => Get.back(),
              // 返回事件
              splashColor: Colors.grey,
              highlightColor: Colors.grey,
              child: Container(
                margin: const EdgeInsets.all(5),
                child: Icon(
                  Icons.arrow_back,
                  color: widget.backColor,
                ),
              ),
            ),
            Container(
              // 标题
              width: 150,
              alignment: Alignment.center,
              margin: const EdgeInsets.only(top: 5, right: 12),
              child: Text(
                widget.title,
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
                style: const TextStyle(color: Colors.black87, fontSize: 16),
              ),
            ),
            Container(
              child: widget.isShowEnd
                  ? InkWell(
                      onTap: () {
                        print("点击了右侧按钮");
                      },
                      child: Container(
                        margin: const EdgeInsets.all(10),
                        child: Text(
                          widget.endText,
                          style: const TextStyle(
                            fontSize: 13,
                            color: ColorStyle.color_B8C0D4,
                          ),
                        ),
                      ),
                    )
                  : Container(),
            ),
          ],
        ),
      ),
    );
  }
}
